package com.xingongchang.baolebei.model;

import java.util.HashMap;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import com.external.androidquery.callback.AjaxStatus;
import com.insthub.BeeFramework.Utils.MD5Utils;
import com.insthub.BeeFramework.model.BaseModel;
import com.insthub.BeeFramework.model.BeeCallback;
import com.xingongchang.baolebei.protocol.ALIPAY;
import com.xingongchang.baolebei.protocol.STATUS;

public class AlipayModel extends BaseModel {

	public ALIPAY alipay;
	
	public AlipayModel(Context context) {
		super(context);

	}

	/**
	 * 获取支付宝配置信息
	 */
	public void getAlipay() {

		String url = ProtocolConst.ALIPAY;

		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {

			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {

				AlipayModel.this.callback(url, jo, status);

				try {
					STATUS responseStatus = STATUS.fromJson(jo
							.optJSONObject("status"));

					if (responseStatus.succeed == 1) {
						JSONObject obj = new JSONObject();
						JSONObject alipayobj = obj.getJSONObject("data");
						alipay = ALIPAY.fromJson(alipayobj);
						AlipayModel.this.OnMessageResponse(url, jo, status);
					}

				} catch (JSONException e) {

					e.printStackTrace();
				}

			}

		};


		JSONObject requestJsonObject = new JSONObject();
		String MD5 = MD5Utils.encode("1234567i");
		Map<String, String> params = new HashMap<String, String>();
		try {
			requestJsonObject.put("checkKey", MD5);
		} catch (JSONException e) {

		}

		params.put("json", requestJsonObject.toString());

		cb.url(url).type(JSONObject.class).params(params);
//		ProgressDialog pd = new ProgressDialog(mContext);
//		pd.setMessage(mContext.getResources().getString(R.string.hold_on));
		aq.ajax(cb);

	}

}
